package com.zy.web.controller.bs;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zy.entity.bs.Activity;
import com.zy.pojo.query.bs.ActivityQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.pojo.vos.common.ResultVo;
import com.zy.service.bs.ActivityService;
import com.zy.web.controller.base.BaseController;
import com.zy.web.utils.ResultUtil;
import org.springframework.web.multipart.MultipartFile;

import java.io.Serializable;
import java.util.List;

@RequestMapping({"bs/activity","m/bs/activity"})
@Controller
public class ActivityController extends BaseController {

	@Autowired
	private ActivityService activityService;

	/**
	 * 分页
 	 * 
 	 * @param activityQuery
	 * @param start
	 * @param limit
	 * @return
	 */
	@RequestMapping(value = {"pageActivity","pageActivityForApp"})
	@ResponseBody
	public PageVo pageActivity(ActivityQuery activityQuery, Integer start, Integer limit) {
		return this.activityService.pageActivity(activityQuery, start, limit);
	}

	/**
	 * 新增
	 * 
	 * @param activity
	 * @return
	 */
	@RequestMapping(value = {"saveActivity","saveActivityForApp"}, method = RequestMethod.POST)
	@ResponseBody
	public ResultVo saveActivity(Activity activity) {
		try {
			activity.setCreateUserId(this.getCurrentUser().getId());
			activity.setUserId(this.getCurrentUser().getId());
			this.activityService.saveActivity(activity);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}
	
	/**
	 * 更新
	 * 
	 * @param activity
	 * @return
	 */
	@RequestMapping(value = {"updateActivity","updateActivityForApp"}, method = RequestMethod.POST)
	@ResponseBody
	public ResultVo updateActivity(Activity activity) {
		try {
			activity.setModifyUserId(super.getCurrentUser().getId());
			this.activityService.updateActivity(activity);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 删除
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "removeActivity", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo removeActivity(long id) {
		try {
			this.activityService.removeActivity(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 恢复
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "recover", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo recover(long id) {
		try {
			this.activityService.recover(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 获取首页滚动 活动
	 *
	 * @return
	 */
	@RequestMapping(value = "front/listActivityForHomePage")
	@ResponseBody
	public ResultVo listActivityForHomePage() {
		try {
			return ResultUtil.success((Serializable) this.activityService.listActivityForHomePage());
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	@RequestMapping("front/pageFrontActivity")
	@ResponseBody
	public PageVo pageFrontActivity(ActivityQuery activityQuery, Integer start, Integer limit) {
		return this.activityService.pageFrontActivity(activityQuery, start, limit);
	}

	@RequestMapping("front/listFourActivity")
	@ResponseBody
	public ResultVo listFourActivity() {
		try {
			return ResultUtil.success((Serializable) this.activityService.listFourActivity());
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	@RequestMapping("front/getActivityInfo")
	@ResponseBody
	public ResultVo getActivityInfo(Long id) {
		try {
			return ResultUtil.success(this.activityService.getByPrimaryKey(id));
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 下架活动
	 *
	 * @param activity
	 * @return
	 */
	@RequestMapping(value = {"updateActivityStatusForApp","updateActivityStatus"} , method = RequestMethod.POST)
	@ResponseBody
	public ResultVo updateActivityStatus(Activity activity) {
		try {
			activity.setModifyUserId(super.getCurrentUser().getId());
			this.activityService.updateActivityStatus(activity);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

    @RequestMapping(value = "myActivityList",method = RequestMethod.POST)
    @ResponseBody
    public PageVo myActivityList(Integer start, Integer limit) {
        return this.activityService.myActivity(this.getCurrentUser().getId(), start, limit);
    }

    @RequestMapping(value = "activityInfo",method = RequestMethod.GET)
    @ResponseBody
    public ResultVo myActivityList(Long id) {
        try {
            return ResultUtil.success( this.activityService.getByPrimaryKey(id));
        } catch (Exception e) {
            return ResultUtil.error(log, e);
        }

    }

    @RequestMapping(value = "myManagerActivityList",method = RequestMethod.POST)
    @ResponseBody
    public PageVo myManagerActivityList(Integer start, Integer limit) {
        return this.activityService.myManagerActivityList(this.getCurrentUser().getId(), start, limit);
    }

}